<template>
    <div>
        <h2>房号修改</h2>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">房号名称</td>
                    <td><input type="text" v-model="queryInfo.roomName" /></td>
                </tr>
                <tr>
                    <td align="right">备注</td>
                   <td> <textarea v-model="queryInfo.roomDesc" cols="50" rows="5"></textarea></td>
                </tr>
                <tr>
                    <td align="right">房号状态</td>
                  <td>  <input type="radio" v-model="queryInfo.state" :value="1" />上架
                    <input type="radio" v-model="queryInfo.state" :value="0" />下架</td>
                </tr>
                <tr>
                    <td align="right">手机号</td>
                    <td><input type="text"  v-model="queryInfo.phone"/></td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td><input type="button" value="修改" @click="ok" /></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>


<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { useRouter , useRoute } from 'vue-router'
import axios from 'axios';
let router = useRouter();   
let route = useRoute();
let queryInfo=reactive({
   
  roomName: "",
  roomDesc: " ",
  state: 1,
  phone: "",
  id:route.query.id
})
onMounted(()=>{
    Fantian();
})
const Fantian=()=>{
    axios({
       url: "/api/RooomNumber/GetNumberId",
        method: "get",
        params: {
            id:route.query.id
        }
        
    }).then((res)=>{
        console.log(res)
        queryInfo.roomName=res.data.roomName
        queryInfo.roomDesc=res.data.roomDesc
        queryInfo.state=res.data.state
        queryInfo.phone=res.data.phone
    })
}
let ok=()=>{
    if(queryInfo.roomName==""){
        alert("请输入房号")
        return
    }
    if(queryInfo.roomDesc==""){
        alert("请输入房号描述")
        return
    }
    if(queryInfo.phone==""){
        alert("请输入手机号")
        return
    }
    axios({
        url: '/api/RooomNumber/RoomUpdate',
        method: 'update',
        data: queryInfo
    })
    .then((res)=>{
        console.log(res.data)
       if(res.data>0){
        alert("修改成功")
        router.push({path:"/RoomNumberList"})
       }
       else if(res.data==-1){
        alert("该房间号已存在")
       }
       else{
        alert("添加失败");
       }
    })
}
</script>

<style scoped>

</style>